<template>
  <div class="home">
   <div class="search" @click="onSearch">
    <img src="../../assets/images/logo.jpg" alt="" />
    <van-search
      class="v-search"
      right-icon
      background="#f60"
     
      placeholder="请输入搜索关键词"
    />
  </div>
    <ul class="nav">
      <li v-for="(l, i) in list" :key="i">
        <img :src="l.src" alt="" />
        <p>{{ l.title }}</p>
      </li>
    </ul>
    <div class="markets">
      <a href="" v-for="(l, i) in lists" :key="i">
        <img :src="l.src" alt="">
      </a>
    </div>
    <div class="banner">
        <img src="../../assets/images/qingcang.png" alt="">
    </div>
    <div class="container">
        <ul class="contant">
            <NewList ref="listone"  :refreshdata="refreshdata" :loadmore="loadmore">
                   
              
                    <div class="tile-item" v-for="(x,y) in contant" :key="y" @click="todetail(x)">
                        <img :src="'https://img1.yiwugou.com/'+ x.picture2" alt="">
                        <div class="items">
                        <h3> {{x.title}} </h3>
                        <p> {{x.sellPrice=='999999999999' && '0' && '999999' ?'暂无数据':Math.floor(x.sellPrice/100).toFixed(2)}} </p>    
                        <h4> {{x.startNum == ''? '' :x.startNum +'个起购'}} </h4>
                        <div> {{x.shopName}} </div>
                        </div>                       
                    </div>
                  
                  
              </NewList>
        </ul>
    </div>
  </div>
</template>

<script>

import axios from "axios"
import { Dialog } from "vant";
export default {
  data() {
    return {
      page:0,
      contant:[],
      list: [
        {
          title: "限时秒杀",
          src: require("@/assets/images/miaosha.png"),
        },
        {
          title: "尾货清仓",
          src: require("@/assets/images/qingcang.jpg"),
        },
        {
          title: "爆款优选",
          src: require("@/assets/images/youxuan.jpg"),
        },
        {
          title: "义乌购超市",
          src: require("@/assets/images/chaoshi.jpg"),
        },
        {
          title: "论坛",
          src: require("@/assets/images/luntan.jpg"),
        },
        {
          title: "品牌馆",
          src: require("@/assets/images/pingpai.jpg"),
        },
        {
          title: "产业带",
          src: require("@/assets/images/chanye.png"),
        },
        {
          title: "直播",
          src: require("@/assets/images/zhibo.jpg"),
        },
        {
          title: "转让",
          src: require("@/assets/images/zhuanrang.jpg"),
        },
        {
          title: "求购与库存",
          src: require("@/assets/images/kucun.jpg"),
        },
      ],
      lists: [
        {
          src: require("@/assets/images/yiqu.jpg"),
        },
        {
          src: require("@/assets/images/yiqudong.jpg"),
        },
        {
          src: require("@/assets/images/erqu.jpg"),
        },
        {
          src: require("@/assets/images/sanqu.jpg"),
        },
        {
          src: require("@/assets/images/siqu.jpg"),
        },
        {
          src: require("@/assets/images/wuqu.jpg"),
        },
        {
          src: require("@/assets/images/shichang.jpg"),
        },
        {
          src: require("@/assets/images/shichang1.jpg"),
        },
        {
          src: require("@/assets/images/qingcang.png"),
        },
      ],
    };
  },

  methods:{
      onSearch(){
          console.log(1111);
          this.$router.push({name:"search"})
      },
      todetail(x){
        this.$router.push({name:"details",query:{id:x.id}})
      },
   
   
    refreshdata(callback){
     
       axios.get("http://localhost:3000/list")
        .then(res=>{
            console.log(res);
         
                this.contant =res.data.list[0].recommProductBoList; 
        
        callback();
        })
       
      
    },
    loadmore(cb,cball){
      this.page++;
      // console.log(this.page);
      if(this.page>10){
        cball()
      }else{
        axios.get("http://localhost:3000/list")
        .then(res=>{
         
                this.contant = this.contant.concat(res.data[this.page].recommProductBoList)
           cb()
        })

      }
    }
  
  },

   mounted(){
        axios.get("http://localhost:3000/list")
        .then(res=>{
            console.log(res.data[0]);  
            this.contant =res.data[0].recommProductBoList;
           
        })
    }
};
</script>

<style lang="scss" scoped>
.container{
    .contant{
      height: auto;
      padding-bottom: 40px;
        img{
            width: 100px;
            height: 100px;
        }
    }
}
.search {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: -webkit-box;
  display: flex;
  line-height: 50px;
  height: 50px;
  background: #f60;
  padding: 0 10px;
  color: #fff;
  align-items: center;
  z-index: 9999;
  img {
    width: 50px;
    margin-right: 10px;
    height: 15px;
  }
  .v-search {
    height: 50px;
    width: 290px;

    .van-search__content {
      border-radius: 5px;
    }
  }
}
.tile-item{
    display: flex;
    border-bottom: 1px solid #eee;
    margin-bottom: 3px;
    .items{
        padding: 9px;
    line-height: 1;
    p{
        color: #f90;
        font-size: 14px;
    }
    }
    h3{
            font-size: 14px;
    line-height: 18px;
    color: #333;
    height: 36px;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-weight: bold;
    }
    h4{
      margin: 5px 0;
    }
}
.nav {
  margin-top: 60px;
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  height: 160px;
  justify-content: space-between;

  li {
    width: 72px;
    height: 72px;
    text-align: center;
    img {
      width: 40px;
      height: 40px;
      margin: 0 auto;
    }
    p {
      margin-top: 10px;
    }
  }
}
.banner{
    width: 100%;
    img{
        width: 100%;
        height: auto;
    }
}
.markets {
  // overflow: auto;
  overflow-x: scroll;
  white-space: nowrap;
    &::-webkit-scrollbar {
    display: none;
  }
  width: 100%;
  padding-bottom: 10px;
  font-size: 0;
  a {
    display: inline-block;
    width: 40%;
 
    border-radius: 10px;
    margin-left: 10px;
    background: #eee no-repeat 50% / cover;
    img{
        width: 100%;
        height: 100%;
    }
  }
}
</style>